
package model;

import java.util.Date;
import java.util.List;
import org.codeforsurvive.utils.MySqlUtil;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author Rohmad Raharjo
 */
public class HistoryModel extends BaseModel {
    
    public HistoryModel()
    {
        tableName = "History";
    }
    
    public List getByTimeRange(Date start, Date end)
    {
        List result = null;
        Session session = MySqlUtil.getSessionFactory().openSession();
        Query query = session.createQuery("from " + tableName + " where timestamp between = :start to :end");
        query.setParameter("start", start);
        query.setParameter("end", end);
        result = query.list();
        session.close();

        return result;
    }
    
    public List getByStartDate(Date start)
    {
        List result = null;
        Session session = MySqlUtil.getSessionFactory().openSession();
        Query query = session.createQuery("from " + tableName + " where timestamp between = :start to sysdate");
        query.setParameter("start", start);
        result = query.list();
        session.close();

        return result;
        
    }
    
}
